home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9432 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: wkaufman.us.oracle.com!wkaufman
  2. From: wkaufman@wkaufman.us.oracle.com (William Kaufman)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: malloc question
  5. Date: 10 Mar 1996 17:39:58 GMT
  6. Organization: Oracle Corporation, Redwood Shores CA
  7. Message-ID: <4hv45e$svm@inet-nntp-gw-1.us.oracle.com>
  8. References: <4htonk$350@news.hklink.net>
  9. NNTP-Posting-Host: wkaufman.us.oracle.com
  10.  
  11. In article <4htonk$350@news.hklink.net> alex@station.net (Alex Chu) writes:
  12. ] main()
  13. ] {
  14. ]   PITEM head, current;
  15. ]   head=(PITEM) malloc(sizeof(ITEM));
  16. ]             ^^^^^^^
  17. ]   head->val=1;
  18. ] }
  19. ] I want to know why need to use the type casting PITEM in front of the
  20. ] malloc ?  Please help!
  21.  
  22.     Either:
  23.  
  24.     a) you're using a pre-ANSI compiler which complains that you can't
  25. portably cast from (char *) to (PITEM) (in which case, you could go and
  26. get an ANSI compiler); or,
  27.  
  28.     b) you aren't including <stdlib.h>, where malloc() is defined as
  29. returning (void *), and the compiler thinks it returns (int).
  30.  
  31.                                            -- Bill K.
  32.  
  33. Bill Kaufman             | "I mean ... it's not even been a two-and-two-make-
  34. wkaufman@us.oracle.com   |  five sort of day, it's more like a two-and-two-
  35.                          |  make ... *fish* ..."  -- "Cages", Dave McKean
  36.